<%--
<ANNOTATION.PAGE>
	<fileName> grid.jsp </fileName>
	<author> kfzx-zhulh</author>
	<createDate> 2010-5-4  下午06:23:28 </createDate>
	<lastModifier> 2010-5-4  下午06:23:28 </lastModifier>
	<lastModifyDate> 2010-5-4  下午06:23:28 </lastModifyDate>
	<description>数据表格</Description>
</ANNOTATION.PAGE>
--%>

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="ctp-tag" prefix="ctp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<ctp:include items='borderlayout,panel,toolbar,chain,textfield,button,tabletree,combobox,form,validator,textarea,label,gridlayout,groupbox,menus,grid,statusbar,radiogroup,checkbox,message_ex,validator'/>
		<script type='text/javascript' kind='variant'>	
		var layout;				//上下布局器
		var extToolBar;			//工具条
		var extAddLayout;		//轻量级布局器
		var extNewForm;			//扩展属性新增表单
		var isRequired_checkbox;//是否必选
		var propertyType_combobox;
		</script>
		<script type='text/javascript' kind='event'>
		//ctp.core.log.lvl = ctp.core.loglvl.obj;
		var myurl='<ctp:url href="systemgmt.flowc" flowActionName="extquerylist" params="Language=sessCtx.Language;" />';
		var flag='new';

		function extFormSucc(data){
			var _mContext = "auth_extlist.jsp -> extFormSucc()";
       	 	try {
			var _message;  
			if(flag=="new"){ 
				_message='<ctp:label key="newinbutton"/>';//新增
			}else if(flag=="mod") {
				_message='<ctp:label key="modify"/>';//修改
			}                                                                        
               if(data[0].out_flag=="0"){//提交成功                                                
                    ctpMSB.succeed({title:'<ctp:label key="result_notice"/>',message:_message+'<ctp:label key="ext_success"/>'});//扩展属性成功！
               		extTurnPageGrid.loadData(myurl+'&extTable='+selectCombobox.getValue());	
               		extToolBar.setDisable("_toolbar_button_modify",true);      
                    extToolBar.setDisable("_toolbar_button_del",true); 
                    }else{
            	    var msgErr=',<ctp:label key="errorCode"/>:'+data.errorCode+',<ctp:label key="errorMsg"/>:'+data.errorMsg;
                    ctpMSB.error({title:'<ctp:label key="result_notice"/>',message:_message+'<ctp:label key="ext_error"/>'+msgErr});//扩展属性失败！
               } 
	       	 }
	       	 catch (e) {
	                ctp.core.log.err(_mContext, e.message);
	         }  
          } 
        function setDisable(flag){   
        	extNewForm.setDisableAll(flag);	
        }
        function reset(){
	        if(flag=="new"){ 
	        	setNullValue();//新增的话，重置就是把所有的框都设置为空
			}else if(flag=="mod") {
				setValue();//修改的话，就是把所有的框都设置为修改前的状态
			}  
        }
        function setValue(){
        	 var temp=extTurnPageGrid.getSelectedData()[0];//选择行的数据	  
             extNewForm.getObj("propertyId").setValue(temp.id);//
             extNewForm.getObj("propertyName").setValue(temp.name);//
             extNewForm.getObj("extTable").setItemChecked(temp.table,true);//
             extNewForm.getObj("propertyType").setValue(temp.type);//
             extNewForm.getObj("defaultValue").setValue(temp.defaultvalue);//
             if(temp.required==1){
             	 extNewForm.getObj("isRequired").setChecked(true);
             }else{
            	 extNewForm.getObj("isRequired").setChecked(false);
             }
             extNewForm.getObj("description").setValue(temp.desc);
             extNewForm.getObj("selectKeyValue").setValue(temp.selectKeyValue);
        }
        function setNullValue(){
       	    extNewForm.getObj("propertyId").setValue("");//
            extNewForm.getObj("propertyName").setValue("");//
            extNewForm.getObj("extTable").setItemChecked("CTP_BRANCH",false);
            extNewForm.getObj("extTable").setItemChecked("CTP_USER",false);
            extNewForm.getObj("extTable").setItemChecked("CTP_ROLE",false);
            extNewForm.getObj("propertyType").setValue("0");//
            extNewForm.getObj("defaultValue").setValue("");//
           	extNewForm.getObj("isRequired").setChecked(false);
            extNewForm.getObj("description").setValue("");
            if(propertyType_combobox.getValue()=='3')
            extNewForm.getObj("selectKeyValue").setValue("");
       }
       function extNameQry(){	
	    	   try {
        			if(extToolBar.getValue(0,"right")==""){
        				ctpMSB.error({title:'<ctp:label key="result_notice"/>',message:'<ctp:label key="input_ext_name"/>'});//请输入你要查询的扩展属性名称！
            		}else{
            			var qryNameUrl='<ctp:url href="systemgmt.flowc" flowActionName="queryName" params="Language=sessCtx.Language;" />&extName='+encodeURIComponent(extToolBar.getValue(0,"right"));
            		 	extTurnPageGrid.loadData(qryNameUrl);	
            		 	extToolBar.setDisable("_toolbar_button_modify",true);      
                        extToolBar.setDisable("_toolbar_button_del",true); 
        			}
             } 
             catch (e) {
                 ctp.core.log.err("extNameQry()", e.message);
             }                        
           }
       function extAddForm(){
				flag='new';	
				extNewPanel.getJqDom().show();	
				extNewPanel.setTitle('<ctp:label key="extend_attribute_add"/>');//扩展属性新增
				setNullValue();
				setDisable(false); 
				document._ext_new_form.flowActionName.value="addExt"; 
       }
       function extModForm(){
       		if(extTurnPageGrid.getSelectedRowId().length==0){
        		ctpMSB.alert({title:'<ctp:label key="ext.msgBox.title"/>',message:'<ctp:label key="ext.alert.notselected"/>'});//先选中一个功能节点再进行操作
        		return;
    		}
       	 	flag='mod';
       	 	setDisable(false); 
       	 	extNewPanel.setTitle('<ctp:label key="extend_attribute_modify"/>');	//扩展属性修改
       	 	extNewForm.getObj("propertyId").setDisable(true);
       	 	setValue();
       		document._ext_new_form.flowActionName.value="extmodify";    
       }
       function extDelForm(){
          		try {
          			flag='del';	
          			if(extTurnPageGrid.getSelectedData().length==0){
          				ctpMSB.error({title:'<ctp:label key="result_notice"/>',message:'<ctp:label key="sel_del_ext_name"/>'});
              		}else{
            			ctpMSB.confirm({message:'<ctp:label key="ifdel_ext_stillcontinue"/>',handler:function(tp){
            				if(tp=='ok'){
                			var data = ctp.data.getJSON('<ctp:url href="systemgmt.flowc" flowActionName="extdelete" params="Language=sessCtx.Language" />',{"json.propertyId":ctp.data.jsonToStr(extTurnPageGrid.getSelectedData())});
                			if(data[0].out_flag=='0'){
                				ctpMSB.succeed({title:'<ctp:label key="result_notice"/>',message:'<ctp:label key="delete"/>'+'<ctp:label key="ext_success"/>'});//删除扩展属性成功
                				extTurnPageGrid.loadData(myurl+'&extTable='+selectCombobox.getValue());	
                				extToolBar.setDisable("_toolbar_button_modify",true);      
                			    extToolBar.setDisable("_toolbar_button_del",true); 
                			}else{
                				ctpMSB.error({title:'<ctp:label key="result_notice"/>',message:'<ctp:label key="delete"/>'+'<ctp:label key="ext_error"/>'});//删除扩展属性失败
                			}               				 
            				}
            			}});
          			}
               } 
               catch (e) {
                   ctp.core.log.err("extDelForm()", e.message);
               }
              					 
               
               }
       function extNewFormSubmit(){
    	    if(isRequired_checkbox.isChecked()){
    	    	isRequired_checkbox.setValue("1");
    	    }else{
    	    	isRequired_checkbox.setValue("0");
    	    }
   			extNewForm.submit();
   	   }
		</script>
		<script type='text/javascript' kind='notUi'>
            //================================非UI组件定义片段==========================================================
			var extValidator = new ctp.validator({id:"extFormValidator"});//验证框架
        </script>
		<script type='text/javascript' kind='ui'>				
		function initUI(){

			     h1 = new ctp.ui.grid.header({
                    title:        
					//第一行
                    [[{text:'<ctp:label key="choice"/>'},			//选择
                      {text: '<ctp:label key="seq"/>'},  			//序号
                      {text: '<ctp:label key="attribute_ID"/>'},	//扩展属性ID
                      {text: '<ctp:label key="attribute_name"/>'},	//扩展属性名称
                      {text: '<ctp:label key="extend_table"/>'},	//扩展表名
                      {text: '<ctp:label key="attribute_style"/>'}, //扩展属性类型
                      {text: '<ctp:label key="default"/>'},			//默认值
                      {text: '<ctp:label key="required_item"/>'}
                    ]],
                    rowIdFieldName:"id",
                    attr: [
                    	{
                    		colType:"radiobox"                    		
                    	},
                    	{
                    		colType:"seqnum"
                    	},
                         {
                            fieldName: "id"
                        },
                         {
                            fieldName: "name"
                        },
                        {
                        	fieldName: "table"
                        },
                        {
                        	fieldName: "type_dict"
                        },
                        {
                        	fieldName: "defaultvalue"
                        },
                        {
                        	fieldName: "required_dict"
                        }
                    ]
                });
	                selectCombobox=new ctp.ui.combobox({
	                    id: 'comboboxID',
	                    width: '120px',
	                    items: [{
	                        text: '<ctp:label key="systemmgmt"/>',//系统管理 
	                        value: '%',
	                        selected:true
	                    }, {
	                        text: '<ctp:label key="branch"/>',//机构
	                        value: 'CTP_BRANCH'
	                    }, {
	                        text: '<ctp:label key="user"/>',//用户
	                        value: 'CTP_USER'
	                    }, {
	                        text: '<ctp:label key="role"/>',//角色
	                        value: 'CTP_ROLE'
	                    }],
	                    onChange:function(oldValue,newValue){
	                    		extTurnPageGrid.loadData(myurl+'&extTable='+newValue);		
	                    		extToolBar.setDisable("_toolbar_button_modify",true);      
	                            extToolBar.setDisable("_toolbar_button_del",true); 
	                            }
	                });
	                extToolBar=new ctp.ui.toolbar({
		  	           	id : 'toolbar1',			
			            border : 'bottom',			
	                    leftItems :[{
							        id:"_toolbar_button_new", 
	                                type : 'button',
	                                text : '<ctp:label key="newinbutton"/>',//新增
	                                icon : 'add',
	                                disable : false,
	                                onClick : extAddForm
	                                },'-',{
								   id:"_toolbar_button_modify",
	                               type : 'button',
	                               text : '<ctp:label key="modify"/>',//修改
	                               icon : 'edit',
	                               disable : false,
	                               onClick : extModForm
								 },'-',{
								   id:"_toolbar_button_del",
	                               type : 'button',
	                               text : '<ctp:label key="delete"/>',//删除
	                               icon : 'delete',
	                               disable : false,
	                               onClick: extDelForm
	                             },'-',{
									   id:"_toolbar_combobox",
		                               type : 'combobox',
		                               text : '<ctp:label key="sel_ext"/>',//请选择扩展表
		                               useable : false,
	                                   object: selectCombobox
								}
								], 
					     rightItems :[{
								        id:"_toolbar_textfield_search",
	                                    type : 'textfield',
								        disable : false,
	                                    text : '<ctp:label key="qry_byname"/>',//属性名称搜索：
	                                    object: new ctp.ui.textfield({
	                                               id: '_toolbar_textfield_search',
	                                               width: '100px'
	                                            })
								       },{
								          id:"_toolbar_button_search",
	                                      type : 'button',                                             
	                                      icon : 'search',
	                                      disable : false,
	                                      onClick : extNameQry
								       }]//,                 			
			            //renderTo:layout.panes.north					   
		           });    
	                extTurnPageGrid = new ctp.ui.grid({
	                    id: "id",
	                    header: h1,
	                    height:'100%',
	                    width:'auto',
	                    title: "<ctp:label key='extend_attribute_list'/>",
						//renderTo:layout.panes.north,
						toolbar:extToolBar,
						toolbarPos:'innertop',
						//url:myurl+'&extTable=%',
						footer:new ctp.ui.grid.footer({showRows:7,cacheRows:7})
	                });
                 var extTable_radiogroup=new ctp.ui.radiogroup({
				  	    id: 'extTable',
				  	  	width: '100%',
				  	  	itemWidth: '60px',
						display: 'cols',
						items: [{
                            id: 'CTP_BRANCH',
                            label: '<ctp:label key="branch_table"/>',//机构表
                            value:'CTP_BRANCH'
                         }, {
                            id: 'CTP_USER',
                            label: '<ctp:label key="user_table"/>',  //用户表 
                            value:'CTP_USER'
                         }, {
                            id: 'CTP_ROLE',
                            label: '<ctp:label key="role_table"/>',  //角色表 
                            value:'CTP_ROLE'
                       }],
                       validate: 'rules[required]'
                  });
                isRequired_checkbox=new ctp.ui.checkbox({
                     	 id: 'isRequired',
                         label: '<ctp:label key="required"/>',		 //必输
                         value: '0',
                         checked: false
                 });
                 propertyType_combobox=new ctp.ui.combobox({id: 'propertyType',name:'propertyType',width:'100%',
                	 defaultItems:[{
                	     	text:'textfield',//textfield
                	     	value:'0',
                	     	selected:'true'
                	     }],
                     items: [{
                	id:'textarea',
                    text: 'textarea',				//长文本
                    value: '1'
             		}, {
             		id:'date',
              		text: 'date',				    //日期
              		value: '2'
       				}, {
       				id:'combobox',
           			text: 'combobox',				//多选框
           			value: '3'
    				}, {
           			id:'radiogroup',
               		text: 'radiogroup',				//radiogroup
               		value: '4'
        			}, {
           			id:'checkboxgroup',
               		text: 'checkboxgroup',			//checkboxgroup
               		value: '5'
        			}]  
    			,validate: 'rules[required]'});
                 
  				 var propertyId_textField=new ctp.ui.textfield({id: 'propertyId',name:'propertyId',width:'100%',validate: 'rules[required,letterOrNumber,length[1,10]]'});
				 var propertyName_textField=new ctp.ui.textfield({id: 'propertyName',name:'propertyName',width:'100%',validate: 'rules[required,length[1,100]]'});
				 var defaultValue_textField=new ctp.ui.textfield({id: 'defaultValue',name:'defaultValue',width:'100%',validate: 'rules[length[1,1000]]'});
				 var selectKeyValue_textField = new ctp.ui.textfield({id: 'selectKeyValue',name:'selectKeyValue',width:'100%',validate: 'rules[length[1,1000]]'});
				 var description_textarea=new ctp.ui.textarea({id: 'description',name:'description',rows:3,width:'100%',validate: 'rules[length[1,500]]'});
				 propertyType_combobox.onChange(function selectKeyValue_textField_Show(){
					 if(propertyType_combobox.getValue()=='3'){
						 selectKeyValue_textField.getJqDom().show();
						 extAddLayout.getLabelObj("selectKey").show();
					 }else{
						 selectKeyValue_textField.getJqDom().hide();
						 extAddLayout.getLabelObj("selectKey").hide();
					 }
                	 /*extAddLayout.append({
                			label: {
                				text: '<ctp:label key="selectKeyValue"/>:'
                			},
                			element: selectKeyValue_textField
                	});*/
                 });
                extAddLayout=new ctp.ui.gridlayout({                    
					width: '95%',
					cols: 2,
					align: 'center',
					colSpace: 30,
					defaults: {display: 'h',align: 'center',label:{width:'100px'},element:{type:'textfield'}},					
					items: [
                       [{label: {id:'ext_table_lab',text: '<ctp:label key="extend_table"/><span style="color:red;">*</span>:'},element: extTable_radiogroup},
                        {label: {id:'required_lab',text: '<ctp:label key="required"/>:'},element:isRequired_checkbox},//必输
                        ],
					   [{label: {id:'attstyle_lab',text: '<ctp:label key="attribute_style"/><span style="color:red;">*</span>:'},element: propertyType_combobox},
					    {label: {id:'attid_lab',text: '<ctp:label key="extend_attribute_ID"/><span style="color:red;">*</span>:'},element: propertyId_textField}
					   ],
					   [{label: {id:'attname_lab',text: '<ctp:label key="extend_attribute_name"/><span style="color:red;">*</span>:'},element: propertyName_textField},
					    {label: {id:'defvalue_lab',text: '<ctp:label key="text_default_value"/>:'},element: defaultValue_textField}
					   ],
					   [{colspan: 2,label: {id:'selectKey',text: '<ctp:label key="selectKeyValue"/>:'},element: selectKeyValue_textField }],
					   [{colspan: 2,label: {id:'des_lab',text: '<ctp:label key="describe"/>:'},element: description_textarea }]
					]                            
                });
			    extNewForm = new ctp.form({
                    id: '_ext_new_form',
                    width: '95%', //宽度
                    validator:extValidator,
                    height: '95%', //高度
                    postType:'ajax',			        
			        ajaxPostParam:{success: extFormSucc},                             
                    items: [extAddLayout],
                    buttons: [{
                        id: '_branch_new_form_addButton',
                        text: '<ctp:label key="submit"/>',//提交
                        icon:'apply',
                        onClick: extNewFormSubmit
                        }, {
                        id: '_branch_new_form_resetButton',
                        text: '<ctp:label key="reset"/>',//重置
                        icon:'reload',
                        onClick:reset
                    }]
                });

	
                extTurnPageGrid.selectedFn(
                        function(){
                        	extNewPanel.getJqDom().show();
                        	setValue();
                        	extNewPanel.setTitle('<ctp:label key="extend_attribute_detail"/>');//扩展属性修改");	
                        	setDisable(true); 
                        	extToolBar.setDisable("_toolbar_button_modify",false);      
                            extToolBar.setDisable("_toolbar_button_del",false); 
                 });	    

                extNewPanel=new ctp.ui.panel({
			        id:'extNewPanelId',
			  	    title: '<ctp:label key="extend_attribute_detail"/>',//扩展属性详细信息',
			  	    collapsible: true,
			     	width: 'auto',
			     	height: '100%',
			     	btnstatus: true,
			        items:[extNewForm]//,
			    	//renderTo:layout.panes.center				   
			    }); 
	            layout=new ctp.ui.borderlayout({
                    type: "2E",
                    north__resizable: true,
                    north__size: 0.5,
                    center__resizable: true,
                    center__size: "auto",
                    center__spacing_open: 0,
                    center__items:[extNewPanel],
                    north__items:[extTurnPageGrid],
                    renderTo:'body'
                });
                setDisable(true);   
                extToolBar.setDisable("_toolbar_button_modify",true);      
                extToolBar.setDisable("_toolbar_button_del",true);  
                extTurnPageGrid.loadData(myurl+'&extTable=%');	 
		}
		</script> 
	</head>
	<body  onload='initUI();'>
	<div id="largeDiv"></div>
		<ctp:form name="_ext_new_form" method="post" action="systemgmt.flowc" flowActionName="">	
			    <input type="hidden" name="validCheck">
      			<input type="hidden" name="format"> 
      			<input type="hidden" name="extName"> 
		</ctp:form>
	</body>
</html>

<%--
<ANNOTATION.ACTION>
	<date>	  </date>
	<modifyReason>  </modifyReason>

</ANNOTATION.ACTION>
--%>